package com.tz.init;

import com.tz.AppConfig;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;

/**
 * 用于初始化表
 * Created by Administrator on 2016/8/5.
 */
public class InitTables {
    @Test
    public void testDDL(){
        ApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class);
        LocalSessionFactoryBean lsfb = ac.getBean(LocalSessionFactoryBean.class);
        Configuration cfg = lsfb.getConfiguration();
//		cfg.configure();//读取hibernate.cfg.xml信息
        SchemaExport se = new SchemaExport(cfg);
        //第一个参:sql脚本是否输出到控制台
        //第二个参:sql脚本是否导入到数据库
        se.create(true, true);
    }

}
